const Utils = {
	// 获取地址栏参数
	getQueryString(name) {
		var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
		var r = window.location.search.substr(1).match(reg)
		if (r != null) return unescape(r[2])
		return null
	},
	// 时间格式化
	formatTime(mm) {
		Date.prototype.toLocaleString = function() {
			return `${this.getFullYear()}.${this.getMonth()}.${this.getDate()}`
		}
		var unixTimestamp = new Date(mm)
		var commonTime = unixTimestamp.toLocaleString()
		return commonTime
	},
	// 手机号加密处理
	mdphone(phone) {
		var phoneCondensation = phone.substr(0, 3) + '****' + phone.substr(7)
		return phoneCondensation
	},
	// 人民币格式化
	RowRMB(r) {
		if (value != null && value != '') {
			return (parseFloat(value).toFixed(2) + '').replace(
				/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g,
				'$&,',
			)
		} else {
			if (value != undefined) {
				return '0.00'
			} else {
				return ''
			}
		}
	},
	// 图片转base64
	ChangeBase64(f, callback) {
		var file = f
		var base64
		var reader = new FileReader()
		var img = new Image(),
			width = 1024, //image resize   压缩后的宽
			quality = 0.8, //image quality  压缩质量
			canvas = document.createElement('canvas'),
			drawer = canvas.getContext('2d')
		reader.readAsDataURL(file)
		reader.onload = function() {
			img.src = this.result
		}
		img.onload = function() {
			canvas.width = width
			canvas.height = width * (img.height / img.width)
			drawer.drawImage(img, 0, 0, canvas.width, canvas.height)
			base64 = canvas.toDataURL('image/jpeg', quality)
			callback(base64)
		}
	},
	// 网络加载弹框倒计时 如果超时 则关闭请求的弹框
	loadSetTimeout() {
		setTimeout(() => {}, 3 * 1000)
	},
}

export { Utils }
